package day4;

import java.io.*;

/**
 * ClassName：TestCharStream
 *
 * @Author：小鱼
 * @Create：2025-08-21 14:37
 */
public class TestCharStream {
    public static void main(String[] args) {
        //实例化流对象
        File fileA =new File("D:\\IDEA_project\\JP_Java\\week6\\src\\day4\\a.txt ") ;
        File fileB =new File("D:\\IDEA_project\\JP_Java\\week6\\src\\day4\\b.txt");

        Reader reader = null;
        Writer writer = null;
        try {
            reader= new FileReader(fileA);
            writer = new FileWriter(fileB,true);
            int r = reader.read();
            while (r!=-1){
                writer.write(r);
                r = reader.read();
            }
            writer.flush();
        } catch (Exception e) {
           e.printStackTrace();
        }finally {

            // 关闭流（先关输出流，再关输入流，避免数据丢失）
            try {
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException e) {
                System.out.println("关闭输出流失败：" + e.getMessage());
            }

            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                System.out.println("关闭输入流失败：" + e.getMessage());
            }
        }


        //读a中内容
//        int i = reader.read();
//        System.out.println(i);



    }
}
